/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function(strs) {
  let res = ''
  let index = 0
  while (true) {
    const s = strs[0]?.[index]
    if (s === undefined) return res
    const flag = strs.every(item => item[index] === s)
    if (flag) {
      res += s;
      index += 1
    } else {
      return res
    }
  }
};

let strs = ["flower", "flow", "flight"]
console.log('打印结果：', longestCommonPrefix(strs))